package com.mifan.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface RoleMenuMapper {

    /**
     * TODO 删除旧的角色菜单
     */
    @Delete({
            "<script>",
            "DELETE FROM ums_role_menu WHERE role_id = #{roleId} AND menu_id NOT IN ",
            "<foreach collection='menuIds' item='menuId' open='(' separator=',' close=')'>",
            "#{menuId}",
            "</foreach>",
            "</script>"
    })
    int deleteOldRoleMenus(@Param("roleId") Long roleId, @Param("menuIds") List<Long> menuIds);

    /**
     * TODO 插入新的角色菜单
     */
    @Insert({
        "<script>",
        "INSERT IGNORE INTO ums_role_menu (role_id, menu_id) VALUES ",
        "<foreach collection='menuIds' item='menuId' separator=','>",
        "(#{roleId}, #{menuId})",
        "</foreach>",
        "</script>"
    })
    int insertRoleMenus(@Param("roleId") Long roleId, @Param("menuIds") List<Long> menuIds);
}